package com.wnhz.work.yz.activity;

import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bigkoo.pickerview.OptionsPickerView;
import com.google.gson.Gson;
import com.wnhz.work.yz.BaseActivity;
import com.wnhz.work.yz.MyApplication;
import com.wnhz.work.yz.R;
import com.wnhz.work.yz.bean.Fragment4Bean;
import com.wnhz.work.yz.bean.JsonBean;
import com.wnhz.work.yz.utils.AlbumImagePath;
import com.wnhz.work.yz.utils.BitnapUtils;
import com.wnhz.work.yz.utils.GetJsonDataUtil;
import com.wnhz.work.yz.utils.Url;
import com.wnhz.work.yz.utils.xutils3.MyCallBack;
import com.wnhz.work.yz.utils.xutils3.XUtil;
import com.wnhz.work.yz.view.MyDatePicker;
import com.wnhz.work.yz.view.PickerView;
import com.wnhz.work.yz.view.SkillBookPop;

import org.json.JSONException;
import org.json.JSONObject;
import org.xutils.image.ImageOptions;
import org.xutils.x;

import java.io.File;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * ----账户管理
 */
public class UserInfoManagerActivity extends BaseActivity implements View.OnClickListener {
    private static final String TAG = "UserInfoManagerActivity";

    private ImageView iv_edit_head;
    private TextView tv_edit_name;
    private TextView tv_edit_realName;
    private TextView tv_edit_sex;
    private TextView tv_edit_birth;
    private TextView tv_edit_industry;
    private TextView tv_edit_position;
    private TextView tv_edit_company;
    private TextView tv_edit_address;
    private RelativeLayout rl_realName;

    private String inputName, inputRealName, inputSex, inputBirth, inputInstudry, inputPosition, inputCompany, inputAddress;

    /**
     * ------头像点击
     */
    private WindowManager.LayoutParams lp;
    private SkillBookPop menuWindow;
    private final int FROM_CAMERA_CODE = 111;// 调用相机更改背景图片的请求code
    private final int FROM_ALBUM_CODE = 112;// 调用相册更改背景图片的请求code

    private String imageName;// 原图名称
    private String imagePath;// 原图路径
    private File tempFile;

    private static final String FilesPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/youZhu/Compress/"; // 图片及其他数据保存文件夹
    private static File compressFile = new File(FilesPath);
    private static final String PhotePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/youZhu/"; // 图片及其他数据保存文件夹
    private static File PhoteFilePath = new File(PhotePath);
    private static final DateFormat df = new SimpleDateFormat("yyyyMMddHHmmssSSS");

    List<String> sexLists = new ArrayList<>();

    ImageOptions options = new ImageOptions.Builder()
            //设置加载过程中的图片
            .setLoadingDrawableId(R.mipmap.ic_morentouxiang)
            //设置加载失败后的图片
            .setFailureDrawableId(R.mipmap.ic_morentouxiang)
            //设置使用缓存
            .setUseMemCache(true)
            //设置显示圆形图片
            .setCircular(true)
            //设置支持gif
            .setIgnoreGif(false)
            .build();

    @Override
    protected void onResume() {
        upload();
        super.onResume();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_info_manager);
        initJsonData();
        if (!PhoteFilePath.exists()) {
            PhoteFilePath = new File(PhotePath);
            PhoteFilePath.mkdirs();
        }
        sexLists.add("男");
        sexLists.add("女");
        sexLists.add("保密");

        initTitle();
        initView();
    }

    private TextView title;

    private void initTitle() {
        title = (TextView) findViewById(R.id.view_main_middle_title);
        title.setText("账户管理");
        findViewById(R.id.btn_main_left).setOnClickListener(this);
    }

    private void initView() {
        iv_edit_head = (ImageView) findViewById(R.id.iv_edit_head);
        tv_edit_name = (TextView) findViewById(R.id.tv_edit_name);
        tv_edit_realName = (TextView) findViewById(R.id.tv_edit_realName);
        tv_edit_sex = (TextView) findViewById(R.id.tv_edit_sex);
        tv_edit_birth = (TextView) findViewById(R.id.tv_edit_birth);
        tv_edit_industry = (TextView) findViewById(R.id.tv_edit_industry);
        tv_edit_position = (TextView) findViewById(R.id.tv_edit_position);
        tv_edit_company = (TextView) findViewById(R.id.tv_edit_company);
        tv_edit_address = (TextView) findViewById(R.id.tv_edit_address);
        rl_realName = (RelativeLayout) findViewById(R.id.rl_realName);
        findViewById(R.id.rl_head).setOnClickListener(this);
        findViewById(R.id.rl_name).setOnClickListener(this);
        findViewById(R.id.rl_realName).setOnClickListener(this);
        findViewById(R.id.rl_sex).setOnClickListener(this);
        findViewById(R.id.rl_birthday).setOnClickListener(this);
        findViewById(R.id.rl_industry).setOnClickListener(this);
        findViewById(R.id.rl_position).setOnClickListener(this);
        findViewById(R.id.rl_company).setOnClickListener(this);
        findViewById(R.id.rl_address).setOnClickListener(this);

        upload();
    }

    public void upload() {
        if (MyApplication.getInstance().getUserBean() == null) {
            return;
        }
        showDialog();
        Map<String, Object> map = new HashMap<>();
        map.put("token", MyApplication.getInstance().getUserBean().getToken());
        XUtil.Post(Url.MEMBER_GETUSERINFO, map, new MyCallBack<String>() {
            @Override
            public void onSuccess(String result) {
                closeDialog();
                super.onSuccess(result);

                Log.i(TAG, "onSuccess: My=== " + result);
                Fragment4Bean bean = new Fragment4Bean();
                Gson gson = new Gson();
                bean = gson.fromJson(result, Fragment4Bean.class);

                x.image().bind(iv_edit_head, bean.getPerson_img(), options);
                tv_edit_name.setText(bean.getRealname());
                if ("0".equals(bean.getIsexamine())) {
                    tv_edit_realName.setText("资料未审核");
//                    rl_realName.setFocusable(false);
//                    rl_realName.setFocusableInTouchMode(false);
//                    rl_realName.setEnabled(false);
                } else if ("1".equals(bean.getIsexamine())) {
                    tv_edit_realName.setText("资料通过审核");
                    rl_realName.setFocusable(false);
                    rl_realName.setFocusableInTouchMode(false);
                    rl_realName.setEnabled(false);
                } else if ("2".equals(bean.getIsexamine())) {
                    tv_edit_realName.setText("审核失败");
                } else if ("3".equals(bean.getIsexamine())) {
                    tv_edit_realName.setText("提交审核");
                    rl_realName.setFocusable(false);
                    rl_realName.setFocusableInTouchMode(false);
                    rl_realName.setEnabled(false);
                }
                switch (Integer.parseInt(bean.getSex())) {
                    case 0:
                        tv_edit_sex.setText("保密");
                        break;
                    case 1:
                        tv_edit_sex.setText("男");
                        break;
                    case 2:
                        tv_edit_sex.setText("女");
                        break;
                }
                try {
                    Log.e("----", bean.getBirth() + "");
                    String a[] = bean.getBirth().split(" ");
                    tv_edit_birth.setText(a[0]);
                } catch (Exception e) {
                    tv_edit_birth.setText(bean.getBirth());
                }
                tv_edit_industry.setText(bean.getProfession());
                tv_edit_position.setText(bean.getPosition());
                tv_edit_company.setText(bean.getCompany());

                String province = bean.getProvince();
                String city = bean.getCity();
                String district = bean.getDistrict();
                String addr = province + "-" + city + "-" + district;
                tv_edit_address.setText(addr);
            }

            @Override
            public void onFinished() {
                closeDialog();
                super.onFinished();
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                closeDialog();
                super.onError(ex, isOnCallback);
            }
        });
    }


    @Override
    public void onClick(View v) {

        Intent intent;
        switch (v.getId()) {
            case R.id.btn_main_left:
                finish();
                break;

            //修改头像
            case R.id.rl_head:
                showPopmenu(v);
                break;

            //姓名
            case R.id.rl_name:
                break;

            //实名认证
            case R.id.rl_realName:
                intent = new Intent(this, IdConfirmActivity.class);
                startActivity(intent);
                break;

            //性别
            case R.id.rl_sex:
                //  showPopSexWindow(v, sexLists);
                OptionsPickerView pvOptions = new OptionsPickerView.Builder(this, new OptionsPickerView.OnOptionsSelectListener() {
                    @Override
                    public void onOptionsSelect(int options1, int option2, int options3, View v) {
                        tv_edit_sex.setText(sexLists.get(options1));

                        changeSexMessage();
                    }
                }).setTitleSize(12)//标题文字大小
                        // .setTitleText("预算系数")
                        .setTitleBgColor(getResources().getColor(R.color.dialog_title))//标题背景颜色 Night mode
                        .setTitleColor(getResources().getColor(R.color.dialog_title))//标题文字颜色)//标题文字颜色
                        .setSubmitColor(getResources().getColor(R.color.text_two))//确定按钮文字颜色
                        .setCancelColor(getResources().getColor(R.color.text_two))//取消按钮文字颜色
                        .build();
                pvOptions.setPicker(sexLists);
                pvOptions.show();
                break;

            //生日
            case R.id.rl_birthday:
                showDateDialog();
                break;

            //行业
            case R.id.rl_industry:
                intent = new Intent(this, ChangeUserMessage.class);
                intent.putExtra("title", "行业");
                intent.putExtra("str", tv_edit_industry.getText().toString());
                startActivity(intent);
                break;

            //职业
            case R.id.rl_position:
                intent = new Intent(this, ChangeUserMessage.class);
                intent.putExtra("title", "职业");
                intent.putExtra("str", tv_edit_position.getText().toString());
                startActivity(intent);
                break;

            //公司名称
            case R.id.rl_company:
                intent = new Intent(this, ChangeUserMessage.class);
                intent.putExtra("title", "公司名称");
                intent.putExtra("str", tv_edit_company.getText().toString());
                startActivity(intent);
                break;

            //地址
            case R.id.rl_address:
//                intent = new Intent(UserInfoManagerActivity.this, AlertAddress.class);
//                intent.putExtra("from", "UserInfoManagerActivity");
//                startActivityForResult(intent, 115);
//                overridePendingTransition(R.anim.push_up_in, R.anim.push_up_out);

                ShowPickerView();
                break;

            default:
                break;
        }

    }

    private void ShowPickerView() {// 弹出选择器

        OptionsPickerView pvOptions = new OptionsPickerView.Builder(this, new OptionsPickerView.OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                //返回的分别是三个级别的选中位置
                String tx = options1Items.get(options1).getPickerViewText() + "-" +
                        options2Items.get(options1).get(options2) + "-" +
                        options3Items.get(options1).get(options2).get(options3);
//                tv_city.setText(tx);
                changeAddressMessage(tx);


//                Toast.makeText(.this,tx,Toast.LENGTH_SHORT).show();
            }
        })

                .setTitleBgColor(Color.WHITE)//标题背景颜色 Night mode
                .setTitleColor(getResources().getColor(R.color.text))//标题文字颜色)//标题文字颜色
                .setSubmitColor(getResources().getColor(R.color.main_color))//确定按钮文字颜色
                .setCancelColor(getResources().getColor(R.color.main_color))//取消按钮文字颜色.build();
                .build();
        /*pvOptions.setPicker(options1Items);//一级选择器
        pvOptions.setPicker(options1Items, options2Items);//二级选择器*/
        if (options1Items.size() == 0) {
            initJsonData();
            return;
        }
        pvOptions.setPicker(options1Items, options2Items, options3Items);//三级选择器
        pvOptions.show();
    }

    private ArrayList<JsonBean> options1Items = new ArrayList<>();
    private ArrayList<ArrayList<String>> options2Items = new ArrayList<>();
    private ArrayList<ArrayList<ArrayList<String>>> options3Items = new ArrayList<>();

    private void initJsonData() {//解析数据

        /**
         * 注意：assets 目录下的Json文件仅供参考，实际使用可自行替换文件
         * 关键逻辑在于循环体
         *
         * */
        String JsonData = new GetJsonDataUtil().getJson(this, "province.json");//获取assets目录下的json文件数据

        ArrayList<JsonBean> jsonBean = GetJsonDataUtil.parseData(JsonData);//用Gson 转成实体

        /**
         * 添加省份数据
         *
         * 注意：如果是添加的JavaBean实体，则实体类需要实现 IPickerViewData 接口，
         * PickerView会通过getPickerViewText方法获取字符串显示出来。
         */
        options1Items = jsonBean;

        for (int i = 0; i < jsonBean.size(); i++) {//遍历省份
            ArrayList<String> CityList = new ArrayList<>();//该省的城市列表（第二级）
            ArrayList<ArrayList<String>> Province_AreaList = new ArrayList<>();//该省的所有地区列表（第三极）

            for (int c = 0; c < jsonBean.get(i).getCityList().size(); c++) {//遍历该省份的所有城市
                String CityName = jsonBean.get(i).getCityList().get(c).getName();
                CityList.add(CityName);//添加城市

                ArrayList<String> City_AreaList = new ArrayList<>();//该城市的所有地区列表

                //如果无地区数据，建议添加空字符串，防止数据为null 导致三个选项长度不匹配造成崩溃
                if (jsonBean.get(i).getCityList().get(c).getArea() == null
                        || jsonBean.get(i).getCityList().get(c).getArea().size() == 0) {
                    City_AreaList.add("");
                } else {

                    for (int d = 0; d < jsonBean.get(i).getCityList().get(c).getArea().size(); d++) {//该城市对应地区所有数据
                        String AreaName = jsonBean.get(i).getCityList().get(c).getArea().get(d);

                        City_AreaList.add(AreaName);//添加该城市所有地区数据
                    }
                }
                Province_AreaList.add(City_AreaList);//添加该省所有地区数据
            }

            /**
             * 添加城市数据
             */
            options2Items.add(CityList);

            /**
             * 添加地区数据
             */
            options3Items.add(Province_AreaList);
        }
    }

    private void showDateDialog() {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        Date curDate = new Date(System.currentTimeMillis());//获取当前时间
        String str = formatter.format(curDate);
        MyDatePicker dataPicker = new MyDatePicker(UserInfoManagerActivity.this);
        dataPicker.selectDateDialog(tv_edit_birth, str, "birth");
    }

    /**
     * 图片上传的弹出popwindow
     *
     * @param view
     */
    public void showPopmenu(View view) {
        menuWindow = new SkillBookPop(this, menuItemsOnClick);
        menuWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {

            public void onDismiss() {
                WindowManager.LayoutParams lp = getWindow().getAttributes();
                lp.alpha = 1f;
                getWindow().setAttributes(lp);
            }
        });

        // 显示窗口位置
        menuWindow.showAtLocation(view, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
        // 设置layout在PopupWindow中显示的位置
        lp = getWindow().getAttributes();
        lp.alpha = 0.6f;
        getWindow().setAttributes(lp);

    }


    private boolean hasSdcard() {
        if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * 弹出pop的菜单点击事件
     */
    private View.OnClickListener menuItemsOnClick = new View.OnClickListener() {
        Intent intent = null;

        public void onClick(View v) {
            menuWindow.dismiss();
            switch (v.getId()) {
                case R.id.from_camera2:

                    intent = new Intent("android.media.action.IMAGE_CAPTURE");
                    // 判断存储卡是否可以用，可用进行存储
                    if (hasSdcard()) {
                        String time = System.currentTimeMillis() + "";
                        imageName = time + ".jpg";
                        intent.putExtra(MediaStore.EXTRA_OUTPUT,
                                Uri.fromFile(new File(Environment.getExternalStorageDirectory() + "/youZhu/", imageName)));
                    }
                    startActivityForResult(intent, FROM_CAMERA_CODE);

                    break;
                case R.id.from_album2:

                    Intent intent = new Intent(Intent.ACTION_PICK,
                            android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                    startActivityForResult(intent, FROM_ALBUM_CODE);

                    break;

                default:
                    break;
            }
        }
    };

    private void changeAddressMessage(final String tx) {
        //  showDialog();
        String txs[] = tx.split("-");
        Map<String, Object> map = new HashMap<>();
        map.put("token", MyApplication.getInstance().getUserBean().getToken());
        map.put("province", txs[0]);
        map.put("city", txs[1]);
        map.put("district", txs[2]);
        XUtil.Post(Url.MEMBER_SETMEMBERINFO, map, new MyCallBack<String>() {
            @Override
            public void onSuccess(String result) {
                closeDialog();
                super.onSuccess(result);
                Log.i(TAG, "onSuccess: city= " + result);
                try {
                    JSONObject jsonObject = new JSONObject(result);
                    String res = jsonObject.optString("result");
                    String info = jsonObject.optString("info");
//                    if ("-1".equals(res)) {
//                        //info = "请重新登录";
//                        MyToast("请重新登录");
//                        startActivity(new Intent(UserInfoManagerActivity.this, LoginNewActivity.class));
//                        return;
//                    }
                    if ("1".equals(res)) {
                        tv_edit_address.setText(tx);
                        MyToast(info);
                    } else {
                        MyToast(info);
                    }

                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFinished() {
                closeDialog();
                super.onFinished();
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                closeDialog();
                super.onError(ex, isOnCallback);
            }
        });

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        super.onActivityResult(requestCode, resultCode, data);

        switch (requestCode) {
            //相册
            case FROM_ALBUM_CODE:

                if (null != data) {
                    // 得到图片的全路径
                    Uri uri = data.getData();
                    String imagePath = AlbumImagePath.getPath(this, uri);
                    System.out.println("imagePath**====www==" + imagePath);
                    updateImage(imagePath, uri);
                }
                break;
            //拍照
            case FROM_CAMERA_CODE:
                boolean hasSdcard = hasSdcard();
                if (hasSdcard) {
                    tempFile = new File(Environment.getExternalStorageDirectory() + "/youZhu/", imageName);
                    Uri uri = Uri.fromFile(tempFile);
                    String imagePath = tempFile.getAbsolutePath();
                    File file = new File(imagePath);
                    if (!file.exists()) {
                        return;
                    }
                    updateImage(imagePath, uri);
                } else {
                    MyToast("未找到存储卡，无法存储照片！");
                }
                break;
            //地址
            case 115:

                if (resultCode == 333) {
                    if (data != null) {
                        tv_edit_address.setText(data.getStringExtra("address"));

                    }
                }


                break;

            default:
                break;
        }

    }

    private void updateImage(String imagePath, Uri uri) {
        if (null == imagePath) {
            return;
        }
        x.image().bind(iv_edit_head, "file://" + imagePath, options);
        upHeadImage(imagePath);
    }

    private void upHeadImage(String imagePath) {
        if (null == imagePath) {
            return;
        }
        showDialog();
        Map<String, Object> map = new HashMap<>();
        map.put("token", MyApplication.getInstance().getUserBean().getToken());

        String targetPath = imagePath;
        //调用压缩图片的方法，返回压缩后的图片path
        String compressImage = BitnapUtils.compressImage(targetPath, targetPath, 30);
        File compressedPic = new File(compressImage);
        map.put("headimg", compressedPic);
        Log.i(TAG, "upHeadImage: = " + imagePath);
        XUtil.Post(Url.MEMBER_CHANGEHEADIMG, map, new MyCallBack<String>() {
            @Override
            public void onSuccess(String result) {
                closeDialog();
                super.onSuccess(result);
                Log.i(TAG, "onSuccess: headimg= " + result);
                try {
                    JSONObject jsonObject = new JSONObject(result);
                    String res = jsonObject.optString("result");
                    String message = jsonObject.optString("info");
                    String url = jsonObject.optString("url");
//                    if ("-1".equals(res)) {
//                        //info = "请重新登录";
//                    MyToast("请重新登录");
//                        startActivity(new Intent(UserInfoManagerActivity.this, LoginNewActivity.class));
//                        return;
//                    }
                    if ("1".equals(res)) {
                        MyToast(message);
                        MyApplication.getInstance().getUserBean().setHeadUrl(url);
                    } else {
                        MyToast(message);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFinished() {
                closeDialog();
                super.onFinished();
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                closeDialog();
                super.onError(ex, isOnCallback);
            }
        });
    }

    /**
     * -----修改性别弹wheel
     */
    private String pickIndex, pickCard;

    private void showPopSexWindow(View view, final List<String> list) {

        // 一个自定义的布局，作为显示的内容
        View contentView = LayoutInflater.from(this).inflate(R.layout.pop_educate, null);
        PickerView picker = (PickerView) contentView.findViewById(R.id.picker_educate);
        TextView pickersure = (TextView) contentView.findViewById(R.id.picker_submit);
        TextView pickercancel = (TextView) contentView.findViewById(R.id.picker_cancel);
        final PopupWindow popupWindow = new PopupWindow(contentView, LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT, true);
        ArrayList<Object> str = new ArrayList<Object>();
        for (int i = 0; i < list.size(); i++) {
            str.add(list.get(i));
        }

        picker.setData(str);
        int size = list.size();
        int defaultNum = size / 2;
        pickCard = str.get(defaultNum).toString();
        picker.setOnSelectListener(new PickerView.onSelectListener() {

            @Override
            public void onSelect(String text) {
                pickCard = text;
            }
        });

        pickercancel.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                popupWindow.dismiss();
            }
        });
        pickersure.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (null != pickCard) {
                    tv_edit_sex.setText(pickCard);

                    changeSexMessage();
                }
                popupWindow.dismiss();
            }
        });

        // 如果不设置PopupWindow的背景，无论是点击外部区域还是Back键都无法dismiss弹框
        // 我觉得这里是API的一个bug

        popupWindow.setBackgroundDrawable(new BitmapDrawable());
        popupWindow.setOutsideTouchable(true);
        // 设置好参数之后再show
        // popupWindow.showAsDropDown(view);
        popupWindow.showAtLocation(findViewById(R.id.root_userinfo), Gravity.BOTTOM, 0, 0);
    }

    private String sex;
    private String birthday;

    private void changeSexMessage() {
        showDialog();
        sex = tv_edit_sex.getText().toString();
        birthday = tv_edit_birth.getText().toString();
        int s = 0;
        if ("男".equals(sex)) {
            s = 1;
        } else if ("女".equals(sex)) {
            s = 2;
        } else if ("保密".equals(sex)) {
            s = 0;
        }
        Map<String, Object> map = new HashMap<>();
        map.put("token", MyApplication.getInstance().getUserBean().getToken());
        map.put("sex", s);
        Log.i(TAG, "onSuccess: sex= " + s);
        XUtil.Post(Url.MEMBER_SETMEMBERINFO, map, new MyCallBack<String>() {
            @Override
            public void onSuccess(String result) {
                closeDialog();
                super.onSuccess(result);
                Log.i(TAG, "onSuccess: sex= " + result);
                try {
                    JSONObject jsonObject = new JSONObject(result);
                    String res = jsonObject.optString("result");
                    String info = jsonObject.optString("info");
                    if ("1".equals(res)) {
                        MyToast(info);
                    } else {
                        MyToast(info);
                    }

                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFinished() {
                closeDialog();
                super.onFinished();
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                closeDialog();
                super.onError(ex, isOnCallback);
            }
        });
    }


}
